<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('order_view_page_title'));
$this->headLink()
    	->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    	->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    	->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
    	->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css');
    	
$this->headScript()
		->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
		->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
		->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
		->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js');
?>
<style>
    .prefix_1 .t_a_bottom span{
        height:26px;
        line-height:26px;
        text-align:right;
        width:140px;
    }
    .prefix_1 .t_a_bottom label {
        display:block;
        float:left;
        height:26px;
        margin-right:0px;
        text-align:left;
        line-height:26px;
        width:130px;
    }
</style>
<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'order_order_list'); ?>"><?php echo $this->translator('order_list_breadcump'); ?></a></span>
    <span><?php echo $this->translator('order_view_breadcump'); ?></span>
</div>

<?php if(!$this->isAllowed):?>
<div class="grid_12"><?php echo $this->translator('order_view_permission_guide');?></div>
<?php else:?>
<?php $order = $this->order?>
<!--order info form-->
<form method="post" action="" id="addorderForm">
    <div class="grid_12 t_a_bottom">
        <div class="clearfix t_a_bottom">
            <div class="grid_12 alpha">
                <?php if($this->allow('add-job', 'assignment', 'assignment')):?>
                <a target="_blank" href="<?php echo $this->url(array('order_id' => $this->order->order_id), 'assignment_assignment_add_job')?>" class="t_a_ui_button_link"><span><?php echo $this->translator('order_assign_order'); ?></span></a>
                <?php endif;?>
                <?php if($this->allow('tracking')):?>
                <a href="<?php echo $this->url(array('order_id' => $this->order->order_id), 'order_order_tracking')?>" class="t_a_ui_button_link"><span><?php echo $this->translator('order_order_edit_status'); ?></span></a>
                <?php endif;?>
            </div>

        </div>
        <!--<?php if($this->allow('edit')):?>
        <a href="<?php echo $this->url(array('order_id' => $this->order->order_id), 'order_order_edit'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('order_edit_order'); ?></span></a>
        <?php endif;?>
        <?php if($this->allow('duplicate')):?>
         <input type="button" id="btnDuplicate" value="<?php echo $this->translator('order_duplicate_order'); ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
        <?php endif;?>
        <?php if($this->allow('print')):?>
         <input onclick="window.open('<?php echo $this->url(array("order_id" => $this->order->order_id), "order_order_print"); ?>','_blank');" type="button" id="btnPrint" value="<?php echo $this->translator('permisson_order_print'); ?>" />
        <?php endif;?>-->
    </div>
</form>
<!--end order info form-->

<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <div class="grid_5"">
                    <label><?php echo $this->translator('order_id'); ?>:</label>
                    <span><?php echo $order->order_invoice?$order->order_invoice:'-';?></span>
                </div>
                <div class="grid_5">
                    <label><?php echo $this->translator('order_created_date'); ?>:</label>
                    <span><?php echo $order->order_created_date?date('d-m-Y', strtotime($order->order_created_date)):'-';?></span>
                </div>
                <div class="grid_5">
                    <label><?php echo $this->translator('order_modify_date'); ?>:</label>
                    <span><?php echo $order->order_modified_date?date('d-m-Y', strtotime($order->order_modified_date)):'-';?></span>
                </div>
                <div class="grid_5">&nbsp;</div>
                <div class="grid_5">
                    <label><?php echo $this->translator('order_customer'); ?>:</label>
                    <span><?php echo $this->translator('order_customer_id'); ?>: <?php echo $order->customer_id;?></span>
                </div>
                <div class="grid_5">
                    <label>&nbsp;</label>
                    <span><?php echo $this->translator('order_customer_name'); ?>:
                        <?php if($this->allow('info', 'customer', 'customer')):?>
                        <a href="<?php echo $this->url(array('user_id' => $order->customer_id), 'customer_customer_info');?>"><?php echo $order->full_name?$order->full_name:$order->user_name;?> <?php echo ($this->e_name)?'('.$this->e_name.')':null;?></a>
                        <?php else:?>
                        <?php echo $order->full_name?$order->full_name:$order->user_name;?> <?php echo ($this->e_name)?'('.$this->e_name.')':null;?>
                        <?php endif;?>
                    </span>
                </div>
                <div class="grid_5">
                    <label><?php echo $this->translator('order_tracking_status'); ?>:</label>
                    <span><?php echo ($this->t_status->code)?$this->translator('order_tracking_status_'.$this->t_status->code):'-'?></span>
                </div>
            </div>

            <div class="grid_5 omega">
                <div class="grid_5">
                    <label><?php echo $this->translator('order_status'); ?>:</label>
                    <span>
                        <?php if($order->order_status == 'canceled'):?>
                        <font color="Red"><?php echo $this->translator('order_'.$order->order_status);?></font>
                        <?php else:?>
                        <font color="Green"><?php echo $this->translator('order_'.$order->order_status);?></font>
                        <?php endif;?>
                    </span>
                </div>
                <div class="grid_5">
                    <label><?php echo $this->translator('order_total_amount'); ?>:</label>
                    <span><?php echo $order->order_total_amount;?> <?php echo $order->order_total_amount_currency;?></span>
                </div>
                <div class="grid_5">
                    <label><?php echo $this->translator('order_modify_amount'); ?>:</label>
                    <span><?php echo ($order->order_modify_amount)?$order->order_modify_amount:'-';?> <?php echo $order->order_modify_amount_currency;?></span>
                </div>
                <div class="grid_5">
                    <label><?php echo $this->translator('order_total_shipping_cost'); ?>:</label>
                    <span><?php echo $order->order_total_shipping_cost;?></span>
                </div>
            </div>
        </div>
    </div>

    <!--Evaluation -->
    <?php if($this->allow('evaluation', 'customer', 'customer') && $this->t_status->code == 'finished'):?>        
    <div class="prefix_1 suffix_1" style="padding-top:5px;">
        <div class="clearfix t_a_bottom">
            <div class="grid_10 t_a_bottom alpha">
                <div class="grid_10">
                    <h3><?php echo $this->translator('order_view_rating_buyer');?></h3>
                    <hr/>
                </div>
                <div class="grid_10 alpha">
                    <?php if($this->orderEval && null != $this->orderEval->buyer_user_id):?>
                    <div class="grid_10">
                        <label><?php echo $this->translator('order_view_point');?>:</label>
                        <span><?php echo $this->orderEval->buyer_to_seller_evaluation;?></span>
                    </div>
                    <div class="grid_10 t_a_bottom">
                        <label><?php echo $this->translator('order_view_evaluation');?>:</label>
                        <span><?php echo $this->orderEval->buyer_to_seller_feedback;?></span>
                    </div>
                    <?php else:?>
                    <div class="grid_10 t_a_bottom"><?php echo $this->translator('order_buyer_no_evaluate_yet');?></div>
                    <?php endif;?>
                </div>
            </div>
            <div class="grid_10 alpha">
                <div class="grid_10">
                    <h3><?php echo $this->translator('customer_view_evaluation_by_buyer', 'customer');?></h3>
                    <hr/>
                </div>
                <div class="grid_10 alpha">
                    <?php if($this->orderEval && null != $this->orderEval->seller_user_id):?>
                    <div class="grid_10">
                        <label><?php echo $this->translator('order_view_point');?>:</label>
                        <span><?php echo $this->orderEval->seller_to_buyer_evaluation;?></span>
                    </div>
                    <div class="grid_10 t_a_bottom">
                        <label><?php echo $this->translator('order_view_evaluation');?>:</label>
                        <span><?php echo $this->orderEval->seller_to_buyer_feedback;?></span>
                    </div>
                    <?php else:?>
                    <form action="<?php echo $this->url(array(), 'customer_customer_evaluation')?>" method="POST" id="buyerRatingForm">
                        <input type="hidden" value="<?php echo (null != @$this->orderEval->buyer_user_id)?true:false;?>" name="update" />
                        <input type="hidden" value="<?php echo true;?>" name="sEvaluated" />
                        <input type="hidden" value="admin_view_order" name="adminViewOrder" />
                        <input type="hidden" value="<?php echo $order->order_id;?>" name="order_id" />
                        <input type="hidden" value="<?php echo $this->user_enterprise;?>" name="enterprise_id" />
                        <input type="hidden" value="<?php echo $this->user->user_id;?>" name="seller_id" />
                        <input type="hidden" value="<?php echo $order->customer_id;?>" name="customer_id" />
                        <div class="grid_10 t_a_bottom">
                            <label><?php echo $this->translator('order_view_point');?>:</label>
                            <select name="point" style="width:50px">
                                <?php for($n=1;$n<=10;$n++):?>
                                <option value="<?php echo $n;?>"><?php echo $n;?></option>
                                <?php endfor;?>
                            </select>
                        </div>
                        <div class="grid_10 t_a_bottom">
                            <label><?php echo $this->translator('order_view_evaluation');?>:</label>
                            <textarea name="evaluation" style="width:500px; height:150px"></textarea>
                        </div>
                        <div class="grid_10 t_a_bottom">
                            <label>&nbsp;</label>
                            <button type="submit"><span style="height:30px; text-align:center; width:auto;" ><?php echo $this->translator('order_rating_save_button');?></span></button>
                        </div>
                    </form>
                    <?php endif;?>
                </div>
            </div>
        </div>
    </div>
    <?php endif;?>
    <!--End evaluation-->
</div>

<div class="grid_12 t_a_ui_data_list_header">
    <div class="grid_3 alpha"><?php echo $this->translator('order_product_name'); ?></div>
    <div class="grid_3"><?php echo $this->translator('order_values'); ?></div>
    <div class="grid_2"><?php echo $this->translator('order_quantity'); ?></div>
    <div class="grid_2"><?php echo $this->translator('order_amount'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('order_exchange_return_cost'); ?></div>
</div>

<div class="grid_12 t_a_bottom" id="ordersDetail">
    <?php foreach ($this->products as $row):?>
    <?php
        /**
        * Attribute and value info
        **/
        $attValue = isset($this->arrAllAtVal[$row->order_detail_id])?$this->arrAllAtVal[$row->order_detail_id]:null;
    ?>
    <div id="tOrderRow_<?php echo $row->order_id; ?>" class="clearfix t_a_ui_data_list_content">
        <div class="grid_3 alpha"><?php echo $row->product_admin_name?></div>
        <div class="grid_3">        	
        	<?php if($attValue):?>
            	<?php foreach($attValue as $a_t):?>
                <div><b><?php echo $a_t[0];?>:</b> <?php echo $a_t[1];?></div>
            	<?php endforeach;?>
            <?php else:?>
            	<?php echo '-';?>
            <?php endif;?>            
        </div>
        <div class="grid_2"><?php echo $row->order_detail_quantity;?></div>
        <div class="grid_2"><?php echo $row->order_detail_quantity*$row->order_detail_product_price;?> <?php echo $row->order_detail_currency;?></div>
        <div class="grid_1 omega"></div>
    </div>
    <?php endforeach;?>
</div>

<!--Customer notice-->
<?php if(trim($order->customer_notice)):?>
<div class="grid_12 t_a_bottom">
    <div class="t_a_ui_helper_line">
        <h3><?php echo $this->translator('order_view_customer_notice_guide');?></h3>
    </div>
</div>
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom" style="text-align:justify;">
            <?php echo $order->customer_notice;?>
        </div>
    </div>
</div>
<?php endif;?>

<?php endif;?>

<div id="tConfirmBox"></div>
<script type="text/javascript">

$(document).ready(function() {

    $('#btnDuplicate').click(function() {
        var self = this;
        $('#tConfirmBox').html('<?php echo addslashes($this->translator('order_action_duplicate_confirm')); ?>')
            .dialog({
                title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
                closeOnEscape: false,
                resizable: false,
                modal: true,
                open: function(event, ui) {
                    $('.ui-dialog-titlebar-close').hide();
                },
                buttons: {
                    '<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
                        $(this).dialog('destroy');
                    },
                    '<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
                        $(this).dialog('destroy');
                        var order_id = '<?php echo $this->order->order_id;?>';
                        $.ajaxq('news_article', {
                            type: 'POST',
                            url: "<?php echo $this->url(array(), 'order_order_duplicate'); ?>",
                            data: {order_id : order_id},
                            success: function(response) {
                                if (response > 0) {
                                    var href = 'http://'+'<?php echo $_SERVER['HTTP_HOST']?>'+'<?php echo $_SERVER['SCRIPT_NAME']?>'+'/admin/order/edit/duplicate/'+response;
                                    window.location = href;
                                }
                            }
                        });
                    }
                }
            });
    });
});
</script>